﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SaiLing.Domain;
using SaiLing.Domain.Specification;
using SaiLing.Exceptions;
using SaiLing.Paging;
using SaiLing.SingleSignOn.Application.Service.Interfaces.System;
using SaiLing.SingleSignOn.Domain.Entities.System;
using SaiLing.SingleSignOn.Domain.Interfaces.System;
using SaiLing.SingleSignOn.Domain.Specifications.System;
using System.Linq;

namespace SaiLing.SingleSignOn.Application.Service.Providers.System
{
    public class OrganizationMenuAuthorityService : BaseService<OrganizationMenuAuthority>, IOrganizationMenuAuthorityService
    {
        public OrganizationMenuAuthorityService(IUnitOfWork unitOfWork, IOrganizationMenuAuthorityRepository repository) : base(unitOfWork, repository)
        {

        }

        public Task<IEnumerable<OrganizationMenuAuthority>> List(Guid? organizationId, Guid? moduleId, Guid? moduleActionId,Guid? appid)
        {
            var spec = new OrganizationMenuAuthoritySpecification(organizationId, moduleId, moduleActionId, appid);
            return Task.FromResult(GetMany(spec));
        }

        public async Task<int> Save(List<OrganizationMenuAuthority> entities)
        {
            for (int i = 0; i < entities.Count; i++)
            {
                await Add(entities[i]);
            }
            return await SaveChangesAsync();
        }
    }
}
